﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace first_project
{
   abstract class Object2D
    {

        #region Atributes and Variables

       public enum Direction { LEFT, RIGHT, UP, DOWN, STOPPED, }

       protected struct animation
       {

           public int frameWidth;
           public int frameHeight;
           public int frameCount;
           public int frameRate;
           public int mapY;
           public int mapX;
           public int currentFrame;
           public string nome;
           public bool ativa;
           public int quadro_atual;
       }

       protected animation currentAnimation;


        private Texture2D image;
        /// <summary>
        /// Sets the image file for the object
        /// </summary>
        public Texture2D Image
        {
            get { return image; }
            set { image = value;}
        }

        protected Vector2 position;
        /// <summary>
        /// Sets the position to the object
        /// </summary>
        public Vector2 Position
        {
            get { return position; }
            set { position = value; }
        }

        protected SpriteEffects Flip;
       
       /*private Vector2 direction;
        /// <summary>
        /// Sets the direction to the object
        /// </summary>
        public Vector2 Direction
        {
            get { return direction; }
            set { direction = value; }
        }*/
    
        

       
        private Vector2 acceleration;
        /// <summary>
        /// Sets the acceleration to the object
        /// </summary>
        public Vector2 Acceleration
        {
            get { return acceleration; }
            set { acceleration = value; }
        }


        /// <summary>
        /// Sets the Rotation to the object
        /// </summary>
        float rotation = 0f;
        public float Rotation
        {
            get { return rotation; }
            set { rotation = value; }
        }

        /// <summary>
        /// Speed of Object 
        /// </summary>
        private Vector2 speed = new Vector2(0, 0);
        public Vector2 Speed
        {
            get { return speed; }
            set { speed = value; }
        }
        
        private Rectangle collisionRect;
        /// <summary>
        /// Collision rectangle for object
        /// </summary>
        public Rectangle CollisionRect
        {
            get { return collisionRect; }
            set { collisionRect = value; }
        }

        private bool visible;
        /// <summary>
        /// Defines wether of not the object is visible
        /// </summary>
        public bool Visible
        {
            get { return visible; }
            set { visible = value; }
        }

        #endregion

        public Object2D(Texture2D texture)
        {
            this.image = texture;
            //this.position
            this.collisionRect = new Rectangle();
            //this.visible;

        }
        public abstract void Update();

        public void Draw(GameTime gameTime,SpriteBatch spriteBatch)
        {
            if (visible)
            {
                //spriteBatch.Draw(image, position, Color.White);

                if (Visible)
                {

                    currentAnimation.currentFrame = (int)(gameTime.TotalGameTime.TotalSeconds * currentAnimation.frameRate) % currentAnimation.frameCount;


                    spriteBatch.Draw(
                           image,
                           new Rectangle(
                               (int)position.X,
                               (int)position.Y,
                               currentAnimation.frameWidth,
                               currentAnimation.frameHeight),
                           new Rectangle(
                               currentAnimation.currentFrame * currentAnimation.frameWidth,
                               currentAnimation.mapY,
                              currentAnimation.frameWidth,
                               currentAnimation.frameHeight),
                           new Color(
                               1.0f * 1,
                               1.0f * 1,
                               1.0f * 1,
                               1),// 1 = variavel alpha
                           0,//0 = variavel rotation
                           Vector2.Zero,//Zero = variavel pivo
                          Flip,// pode flipar a imagem
                           1);//1 = a camada

                }
            }
        }

    }
}
